Skip to content

feat: Mixpanel 서버 사이드 이벤트 트래킹 추가#216

Open
hyesungoh wants to merge 2 commits intomainfrom
feat/mixpanel-server-events
Open

feat: Mixpanel 서버 사이드 이벤트 트래킹 추가#216
hyesungoh wants to merge 2 commits intomainfrom
feat/mixpanel-server-events

Conversation

@hyesungoh
Copy link
Copy Markdown
Member

개요

Notion 이벤트 명세 Tagging Round 1차 중 서버에서 트리거 가능한 이벤트를 Mixpanel로 전송합니다.
화면 단 트래킹은 별도로 작업 완료. 이 PR은 서버 사이드 이벤트만 다룹니다.

부착된 이벤트 (5개)

이벤트 위치 트리거
complete_login identity/app/GithubLoginFacade.kt GitHub 로그인 성공 직후
complete_login identity/app/AppleLoginFacade.kt Apple 로그인 성공 직후
complete_gotcha gotcha/controller/GotchaController.kt 가챠 응답 per-persona
complete_make_quiz quiz/infra/hibernate/NewQuizCreatedInsertHibernateEventListener.kt Quiz INSERT 후
complete_solve_quiz quiz/infra/hibernate/QuizSolveContextDoneHibernateEventListener.kt Solve context DONE 시
submit_quiz_answer quiz/app/SolveQuizFacade.kt 퀴즈 답변 제출 직후

모든 트래킹 호출은 runCatching 으로 감싸 분석 오류가 비즈니스 로직으로 전파되지 않습니다.
비동기 처리는 기존 프로젝트 패턴인 GracefulShutdownDispatcher.gracefulLaunch 를 사용해 앱 종료 시 in-flight 이벤트가 최대 60초까지 보장됩니다.

운영 환경변수 추가 필요

Key Value
MIXPANEL_PROJECT_TOKEN c09aa30641cc7e222df87f00cdc45fa9
  • 배포 매니페스트(deploy/) 또는 GitHub Actions secret 으로 주입.
  • 토큰이 비어있거나 test 프로파일에서는 자동으로 NoOpEventLogger 로 fallback.

변경 구조

  • 신규: core/event/EventLogger 인터페이스 + Mixpanel/NoOp 구현 + Spring @Configuration
  • 신규: gradle/analytics.gradle (com.mixpanel:mixpanel-java:1.5.4)
  • 추가: application.propertiesmixpanel.project.token=\${MIXPANEL_PROJECT_TOKEN:}
  • 테스트: 각 트래킹 지점에 대한 단위/슬라이스 테스트 추가

작업 외 (다른 repo)

  • complete_merge → render 서비스 (gitanimals repo)
  • complete_create_guild, complete_join_guild → guild 서비스 (별도 repo)

빌드 검증 노트

본 PR 의 변경은 정적 분석으로 검증됨 (import 해소, 시그니처 일치, SDK API 호환, 의존성 classpath). 로컬 환경에 JDK 가 없어 ./gradlew compileKotlin test 는 미실행. CI 빌드에서 1차 검증을 받아주세요.

@hyesungoh hyesungoh requested a review from devxb May 4, 2026 10:33

val gotchaResponses = gotchaFacadeV3.gotcha(token, gotchaType, count)

val userId = MDC.get(USER_ID)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InternalAuth.findUserId() 사용하면 좋을거 같습니다~
userId null이면 예외 대신 silent하게 동작하도록 되면 좋을거 같아요.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견 감사합니다 🙏
말씀해주신 대로 MDC.get 직접 조회 대신 InternalAuth.findUserId() 를 사용하도록 변경했고, userIdnull 이면 트래킹을 건너뛰고 silent 하게 동작하도록 수정했습니다. 테스트도 null 케이스 추가했습니다. (커밋: 6987769)

Comment on lines +88 to +96
eventLogger.track(
eventName = "complete_login",
distinctId = user.id.toString(),
properties = mapOf(
"provider" to "github",
"user_id" to user.id,
"is_new_user" to isNewUser,
),
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runCatching이 반복되는데, eventLogger.track 내부에 runcatching을 넣고 외부에서는 빼면 좋을거 같네용

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 지적 감사합니다 🙏
MixpanelEventLogger.track 내부에 이미 runCatching 이 있는데 호출부에서 중복으로 감싸고 있던 부분을 제거했습니다. EventLogger 인터페이스 KDoc 에도 "절대 throw 하지 않는다" 는 계약을 명시해서 향후 새 구현체/호출부에서도 동일 규칙이 적용되도록 했습니다. 호출부 6곳 모두 정리되었습니다. (커밋: 6987769)

…rnalAuth 도입

- EventLogger.track 계약을 "절대 throw 하지 않음"으로 명시 (KDoc)
- 호출부 6곳의 외부 runCatching/onFailure 제거 (MixpanelEventLogger 내부에서 이미 보장)
- GotchaController가 MDC 직접 조회 대신 InternalAuth.findUserId() 사용, userId null이면 silent skip
@hyesungoh hyesungoh requested a review from devxb May 5, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants